<template>
  <div>
    <el-form @submit.native.prevent class="query-table-form" :inline="true" :model="params">
      <el-form-item>
        <el-input
          v-model="params.customer_name"
          placeholder="借款人/担保客户查询"
          clearable
          @change="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <select-address
          v-model="params.address_code"
          placeholder="地址查询"
          :auto-top="1"
          clearable
          @change="getData()"
        ></select-address>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="params.bank_name"
          placeholder="银行名称查询"
          clearable
          @keyup.enter.native="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" @click="getData()">查询</el-button>
        <el-button
          icon="el-icon-download"
          :loading="exportLoading"
          @click="exportExcel('十二大产业贷')"
        >
          导出
        </el-button>
      </el-form-item>
    </el-form>

    <c-table border v-loading="loading" class="table-sm" :columns="tableColumns" :data="tableData">
      <template v-slot:use="scope">
        <div class="text-truncate" :title="scope.row.funds_use_dir">
          {{ scope.row.funds_use_dir }}
        </div>
      </template>
      <template v-slot:mainBudiness="scope">
        <div class="text-truncate" :title="scope.row.main_business">
          {{ scope.row.main_business }}
        </div>
      </template>
      <template v-slot:status="scope">
        <span class="badge badge-wrap badge-warning">{{ scope.row.statusLabel }}</span>
      </template>
    </c-table>

    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="tableCount"
        @current-change="getData"
      ></el-pagination>
    </div>

    <el-dialog
      append-to-body
      top="30px"
      width="1100px"
      :close-on-click-modal="false"
      :visible.sync="oneIndustryVisible"
    >
      <industry-credit :one-industry="oneIndustry"></industry-credit>
    </el-dialog>
  </div>
</template>
<script>
import IndustryCredit from '@/bank/components/IndustryCredit'
import hndTableMixin from '@/credit/views/province/hnd/hndTableMixin'
import { hndBaseTableColumns } from '@/credit/views/province/hnd/Recommend'
import SelectAddress from '@/components/select/SelectAddress'
export default {
  components: {
    IndustryCredit,
    SelectAddress,
  },
  mixins: [hndTableMixin],
  props: {},
  data() {
    return {
      params: {
        index: 1,
        size: 10,
        customer_name: '',
        'update_apply.gt': 0,
      },
      order: {
        create_time: 'desc',
      },
      tableName: 'datum_one_county_industry',
      tableColumns: [
        ...hndBaseTableColumns,
        { attrs: { label: '项目状态', prop: 'statusLabel', align: 'center' }, slot: 'status' },
        {
          attrs: { label: '操作', align: 'center', width: '100px' },
          operations: [
            { content: '详情', icon: 'fa fa-search', event: this.showCreditFile },
            // { content: '删除', icon: 'fa fa-trash', attrs: { 'class': 'text-danger py-0 px-2' }, event: this.handleDelete }
          ],
        },
      ],

      oneIndustry: {},
      oneIndustryVisible: false,

      applyRow: {},
      applyVisible: false,
    }
  },
  computed: {},
  watch: {},
  created() {
    if (this.isBank) {
      this.params['bank_code.endlike'] = this.user.orgCode
      this.params['orWhere.warranty_amount.gt'] = 300
      this.params['orWhere.warranty_period.eq'] = '36个月以上'
      this.params['orWhere.main_business.eq'] = '其他特色农业产业'
    } else {
      this.params.andWhereOrTemplate = 2
      this.params['andWhereOr.service_id.eq'] = this.clientId
      this.params['andWhereOr.recommend_service.eq'] = this.clientId

      this.params['andWhereOr.warranty_amount.gt'] = 300
      this.params['andWhereOr.warranty_period.eq'] = '36个月以上'
      this.params['andWhereOr.main_business.eq'] = '其他特色农业产业'
    }
    this.getData()
  },
  methods: {
    getParams() {
      return this.params
    },
    handleApply(row = {}) {
      this.applyRow = row
      this.applyVisible = true
    },
    dataAdapter(item) {
      item.loadDate = this.$utils.dateFormat(item.load_date, 'yyyy-MM-dd')
      item.loadEndDate = this.$utils.dateFormat(item.load_end_date, 'yyyy-MM-dd')

      const statusText = []
      if (+item.warranty_amount > 300) {
        statusText.push('担保金额大于300万')
      }
      if (item.warranty_period === '36个月以上') {
        statusText.push('贷款期限大于3年')
      }
      if (item.main_budiness === '其他') {
        statusText.push('主营业务为其他')
      }
      item.statusLabel = statusText.join('、')

      return item
    },
    handleDelete(row = {}) {
      this.$utils
        .msgbox({
          message: `确定删除企业${row.customer_name}?`,
          beforeClose: () =>
            this.$api.deleteData(this.$serviceName, this.formTable, row.customer_related_id),
        })
        .then(() => {
          this.$message.success('删除成功！')
          this.handleSuccess()
        })
        .catch(() => this.$message.error('删除失败，请重试！'))
    },
    showCreditFile(row = {}) {
      this.oneIndustry = row
      this.oneIndustryVisible = true
    },
  },
}
</script>
<style lang="scss" scoped></style>
